var time = sessionStorage.obj;
var today;
if (typeof (time) == "undefined") {
	var today = new Date();
	today.setHours(0, 0, 0, 0);
} else {
	// 重新转换为对象
	obj = JSON.parse(time);
	today = new Date(obj.name);
}
tick();
function tick() {
	var second = today.getSeconds() + 1;
	today.setSeconds(second, 0);
	var timeTick = today.getHours() + "小时" + today.getMinutes() + "分钟"
			+ today.getSeconds() + "秒";
	window.setTimeout("tick()", 1000);
}
window.onbeforeunload = function(event) {
var timelong = today.getTime();
var obj = {
	name : timelong
};
var str = JSON.stringify(obj);
sessionStorage.obj = str;
}

function EbeimService() {
    
    this.login = function(data, success, error) {
    	ebeimAjax({
            url: "/rest/login",
            data: JSON.stringify(data), // '{"name":"' + model.name + '"}',  
            contentType: 'application/json;charset=UTF-8',
            dataType: 'text',
            type: "POST",
            success: success,
            error: error
        });
    }
    
    this.getComputerMessage = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/computer_message/check",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.noAuthorization = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/no_authorization/check",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getCpuRate = function(data, success, error){
    	$.ajax({
            url: "/rest/monitor/cpuRate",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    this.getMessageCode = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/short_message/send",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.oncePasswordUpdate = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/short_message/update_password",
            data: data,
            dataType: 'json',
            type: "POST",
            success: success,
            error: error
        });
    }
    
    this.keyNoBindCheck = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/key_no_bind/check",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }

    this.keyBindCheck = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/key_bind/check",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }

    this.authorizationCodeNoBindCheck = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/authorization_code_no_bind/check",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }

    this.authorizationCodeBindCheck = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/authorization_code_bind/check",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getForgetUser = function(data, success, error){
    	ebeimAjax({
            url: "/rest/noIntercept/user/username",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getFirstPageStatics = function(data, success, error){
    	ebeimAjax({
            url: "/rest/first_page/total",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getDataSourcesByPage = function(data, success, error){
    	ebeimAjax({
            url: "/rest/datasources/list/pages",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getUploadProcessBar = function(data, success, error){
    	$.ajax({
            url: "/rest/upload/process/bar",
            data: data,
            dataType: 'json',
            type: "POST",
            success: success,
            error: error
        });
    }
    
    this.getUploadProcessBarAll = function(data, success, error){
    	$.ajax({
            url: "/rest/upload/process/bar/all",
            data: data,
            dataType: 'json',
            type: "POST",
            success: success,
            error: error
        });
    }
    
    this.deleteUploadProcessBar = function(data, success, error){
    	$.ajax({
            url: "/rest/upload/process/bar/delete",
            data: data,
            dataType: 'json',
            type: "POST",
            success: success,
            error: error
        });
    }
    
    this.addDataSource = function(data, success, error){
    	ebeimAjax({
            url: "/rest/datasources/save",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=UTF-8',
            dataType: 'json',
            type: "POST",
            loadingTxt:"正在计算大小",
            success: success,
            error: error
        });
    }
    
    this.getSystemDirs = function(data, success, error){
    	ebeimAjax({
            url: "/rest/system/dirs",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.sendMobileCode = function(data, success, error){
    	ebeimAjax({
            url: "/rest/send/mobilecode",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.backup = function(data, success, error){
    	ebeimAjax({
            url: "/rest/backup",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getDataSource = function(data, success, error){
    	ebeimAjax({
            url: "/rest/datasources/"+data,
            data: {},
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getFileList = function(data, success, error){
    	ebeimAjax({
            url: "/rest/datasources/files",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    //2015年11月11日17:00:25
    this.getBackuplogs = function(data, success, error){
    	ebeimAjax({
            url: "/rest/backlog/list",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=UTF-8',
            dataType: 'json',
            type: "POST",
            success: success,
            error: error
        });
    }
    
    this.getFileChangeLog = function(data, success, error){
    	ebeimAjax({
            url: "/rest/filechanglog/list",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.recoveryFile = function(data, success, error){
    	ebeimAjax({
            url: "/rest/recovery",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getDownloadProcessBar = function(data, success, error){
    	$.ajax({
            url: "/rest/downlaod/process/bar",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    	
    }
    
    this.deleteDownloadProcessBar = function(data, success, error){
    	$.ajax({
            url: "/rest/download/process/bar/delete",
            data: data,
            dataType: 'json',
            type: "POST",
            success: success,
            error: error
        });
    }
    
    this.deleteDownloadProcessBarByNid = function(data, success, error){
    	ebeimAjax({
            url: "/rest/download/process/bar/delete/nid",
            data: data,
            dataType: 'json',
            type: "POST",
            success: success,
            error: error
        });
    }
    
    this.backup = function(data, success, error){
    	ebeimAjax({
            url: "/rest/backup",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.safeBoxInfo = function(data, success, error){
    	ebeimAjax({
            url: "/rest/datasource/safe_box/info",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    this.updataStatusMany = function(data, success, error){
    	ebeimAjax({
            url: "/rest/datasource/update/status",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    //----------------------邪恶的分割线--------------------------
    this.getMenuTree = function(data, success, error){
    	ebeimAjax({
            url: "/rest/datasource/menu",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
            
    this.getMonitorDatasource = function(data, success, error){
    	ebeimAjax({
            url: "/rest/monitor/datasources/list",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    this.getMonitorPlan = function(data, success, error){
    	ebeimAjax({
            url: "/rest/monitor/datasources/plan",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    this.getMonitor = function(data, success, error){
    	ebeimAjax({
            url: "/rest/monitor/userInfo",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    this.getMonitorAlert = function(data, success, error){
    	ebeimAjax({
            url: "/rest/monitor/warnList",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    //获取目前的系统参数
    this.getSystemInfo = function(data, success, error){
    	ebeimAjax({
            url: "/rest/systemSet/getSysInfo",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    //设置系统变量
    this.setSystemInfo = function(data, success, error){
    	ebeimAjax({
            url: "/rest/systemSet/sysInfo",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getUserInfo = function(data, success, error){
    	ebeimAjax({
            url: "/rest/userinfo",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
   //改变服务系统参数 
    this.changeServiceParam = function(data, success, error){
    	ebeimAjax({
            url: "/rest/monitor/changeServiceParam",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getMonitorNetWorkMonitor = function(data, success, error){
    	ebeimAjax({
            url: "/rest/monitor/net_work_monitor",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    this.getPushMessage = function(data, success, error){
    	$.ajax({
            url: "/rest/pushmessage/list",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.createVersionTreeFolder = function(data, success, error){
    	ebeimAjax({
            url: "/rest/version/tree/createfolder",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.importDs = function(data, success, error){
    	ebeimAjax({
            url: "/rest/datasource/import",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=UTF-8',
            dataType: 'json',
            type: "POST",
            loadingTxt:"正在生成版本树，请稍后...",
            success: success,
            error: error
        });
    }
    
    
    this.getServiceStatus = function(data, success, error){
    	$.ajax({
            url: "/rest/monitor/getServiceStatus",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    this.getMonitorDetailPlan = function(data, success, error){
    	ebeimAjax({
            url: "/rest/monitor/getDetailPlan",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.getUpDownloadFaileds = function(data, success, error){
    	$.ajax({
            url: "/rest/updownload/failed/files",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.upDownloadRetry = function(data, success, error){
    	ebeimAjax({
            url: "/rest/updownload/failed/files/tryagain",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
    this.deleteUpDownloadFailedFiles = function(data, success, error){
    	ebeimAjax({
            url: "/rest/updownload/failed/files/delete",
            data: data,
            dataType: 'json',
            type: "GET",
            success: success,
            error: error
        });
    }
    
//    this.getUserInfo = function(callback){
//        var url = this.url + "/rest/userinfo?timestamp="+new Date().getTime();
//        var client = new RestServiceJs(url);
//        client.findAll(callback);
//    }
    
//    this.getFileList = function(dsId, version, path, callback) {
//        var url = this.url + "/rest/datasources/files?dsId="+dsId+"&version="+version+"&path="+path+"&timestamp="+new Date().getTime();
//        var client = new RestServiceJs(url);
//        client.findAll(callback);
//    }

    /*this.keyNoBindCheck = function(data,callback){
        var url = this.url + "/rest/noIntercept/key_no_bind/check?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.getAjax(data,callback);
    }

    this.keyBindCheck = function(data,callback){
        var url = this.url + "/rest/noIntercept/key_bind/check?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.getAjax(data,callback);
    }

    this.authorizationCodeNoBindCheck = function(data,callback){
        var url = this.url + "/rest/noIntercept/authorization_code_no_bind/check?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.getAjax(data,callback);
    }

    this.authorizationCodeBindCheck = function(data,callback){
        var url = this.url + "/rest/noIntercept/authorization_code_bind/check?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.getAjax(data,callback);
    }

    this.getComputerMessage = function(callback){
        var url = this.url + "/rest/noIntercept/computer_message/check?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.getAjax({},callback);
    }

    this.oncePasswordUpdate = function(data,callback){
        var url = this.url + "/rest/noIntercept/short_message/update_password?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.postAjax(data,callback);
    }

    this.getMessageCode = function(data,callback){
        var url = this.url + "/rest/noIntercept/short_message/send?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.getAjax(data,callback);
    }

    this.sendMobileCode = function(callback){
        var url = this.url + "/rest/send/mobilecode?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.loadTmpl(url,callback);
    }

    this.getPushMessage = function(callback){
        var url = this.url + "/rest/pushmessage/list?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.loadTmpl(url,callback);
    }

    this.backup = function(dsId,dsSecurityRank,dynamicCode,callback){
        var url = this.url + "/rest/backup?dsId=" + dsId+"&dsSecurityRank="+dsSecurityRank+"&dynamicCode="+dynamicCode+"&timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.loadTmpl(url,callback);
    }

    this.getDataSources = function(callback) {
        var url = this.url + "/rest/datasources/list?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.findAll(callback);
    }

    this.getDataSourcesByPage = function(offset,pagesize,dsType,status,name,callback) {
        var url = this.url + "/rest/datasources/list/pages?offset="+offset+"&pagesize="+pagesize+"&dsType="+dsType+"&status="+status+"&name="+name+"&timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.findAll(callback);
    }

    this.getRecoveryRecords = function(id,offset,pagesize,callback){
        var url = this.url + "/rest/recovery/records?id="+id+"&offset="+offset+"&pagesize="+pagesize+"&timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.loadTmpl(url,callback);
    }

    this.deleteRecoveryRecords = function(ids,callback){
        var url = this.url + "/rest/recovery/records/delete?ids="+ids+"&timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.loadTmpl(url,callback);
    }

    this.getDataSource = function(dsId, callback) {
        var url = this.url + "/rest/datasources/"
        var client = new RestServiceJs(url);
        client.find(dsId, callback);
    }

    this.getLineStorageChart = function(callback){
        var url = this.url + "/rest/line/storage/chart?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.findAll(callback);
    }

    this.getBackuplogs = function(json,callback){
        var url = this.url + "/rest/backlog/list?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.post(json, callback);
    }

    this.addDataSource = function(model, callback) {
        var url = this.url + "/rest/datasources/save?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.post(model, callback);
    }

    this.getSystemFiles = function(path, callback) {
        var url = this.url + "/rest/system/files?path="+encodeURIComponent(path)+"&timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.findAll(callback);
    }

    this.getSystemDirs = function(path, callback) {
        var url = this.url + "/rest/system/dirs?path="+encodeURIComponent(path)+"&timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.findAll(callback);
    }

    this.login = function(data, callback) {
        var url = this.url + "/rest/login?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.post(data, callback);
    }

    this.logout = function(callback){
        var url = this.url + "/rest/logout?timestamp="+new Date().getTime();
        var client = new RestServiceJs(url);
        client.findAll(callback);
    }*/
}
